<%@ page contentType="text/html;charset=UTF-8" %>
<%@ include file="/common/taglibs.jsp" %>
<link rel="StyleSheet" href="../../themes/${sessionScope.loginUser.theme}/dtree/dtree.css" type="text/css" />
<script type="text/javascript" src="../../scripts/dtree/dtree.js"></script>
<fmt:message key="menu_address_label1" var="menu_address_label1"/>
<fmt:message key="addressUserTree_label1" var="addressUserTree_label1"/>
<fmt:message key="addressUserTree_label2" var="addressUserTree_label2"/>
<fmt:message key="addressUser_list_label1" var="addressUser_list_label1"/>
<fmt:message key="addressContact_list_label1" var="addressContact_list_label1"/>
<fmt:message key="addressContact_list_label2" var="addressContact_list_label2"/>
<fmt:message key="addressContact_list_label3" var="addressContact_list_label3"/>
<fmt:message key="addressUser_friendGroup_label23" var="addressUser_friendGroup_label23"/>
<fmt:message key="addressUser_friendGroup_label24" var="addressUser_friendGroup_label24"/>
<fmt:message key="addressUser_friendGroup_label25" var="addressUser_friendGroup_label25"/>
<fmt:message key="address_systemuser_label29" var="address_systemuser_label29"/>
<fmt:message key="address_systemuser_label30" var="address_systemuser_label30"/>
<fmt:message key="addressUser_list_label5" var="addressUser_list_label5"/>
<fmt:message key="addressUser_list_label17" var="addressUser_list_label17"/>
<fmt:message key="addressUser_list_label18" var="addressUser_list_label18"/>
<fmt:message key="addressUser_addSystemUser_label6" var="addressUser_addSystemUser_label6"/>
<fmt:message key="addressUser_addSystemUser_label7" var="addressUser_addSystemUser_label7"/>
<fmt:message key="addressUser_addSystemUser_label8" var="addressUser_addSystemUser_label8"/>
<fmt:message key="addressUser_addSystemUser_label9" var="addressUser_addSystemUser_label9"/>

<script type="text/javascript">
function showDetail(divid, url){
		     window.refleshLocalArea(divid,url + '&page=right');
		    // window.parent.navigate(url);
		}
function editsingle_do(entityName, action,remind)
{
    var items = document.getElementsByName('itemlist');
    var count = 0;
    var myid;
    if(items.length>0){
	    for (var i = 0; i < items.length; i++)
	    {
	        if (items[i].checked == true)
	        {
	        	count = count + 1;
	        	myid = items[i].value;
	        }
	    }
	}else{
		if(items.checked == true){
			  count = 1;
			  myid = items.value;
		}
	}
	if (count != 1) {
        alert('${addressUser_friendGroup_label23}' + entityName + '${addressUser_friendGroup_label24}'+remind+'${addressUser_friendGroup_label25}');
        return;
    }

    var form1 = document.forms.ec;
    form1.action = action + "groupId=" + myid;
    form1.submit();
}
  function openwindow(url){
     openwin(url,100,100,500,300,'yes');
     window.close();
  }
  function moveAddress(search_id){
   
     var addressvalue = document.queryform.addressUser.value;
     if(addressvalue!=''){ 
	     var url='<c:url value="/modules/address/addressUser.do?method=joinAddressUser&join=true"/>';
	     url=url+"&addressUser="+addressvalue;
	     url=url+"&search_id="+search_id;
	     moveHint(url);
	 }
  }
  function changetype(){
      var type = document.queryform1.querytype.value;
      var url='<c:url value="/modules/address/addressUser.do?method=list&show=addressuserGroup"/>';
      if(type=='1'){
      url='<c:url value="/modules/address/addressContact.do?method=list&type=0"/>';
      }else if(type=='2'){
      url='<c:url value="/modules/address/addressContact.do?method=list&type=1"/>';
      }
      window.navigate(url);
  }
		function moveHint(action)
		{
		    if (!atleaseOneCheck())
		    {
		        alert('${address_systemuser_label29}');
		        return;
		    }
		    if (confirm("${address_systemuser_label30}"))
		    {
		        var form = document.forms.ec;
		        form.action = action;
		        form.submit();
		    }
		}
		
		function checkvalue(){
  if(document.queryform1.search_smart.value==''){
     alert('${addressUser_addSystemUser_label8}');
      return false;
   }
}
</script>
<script language="javascript">
function sendMessage() {
	var wantSend = "";
    var items = document.getElementsByName('itemlist');
    if(items.length>0) {
	    for (var i = 0; i < items.length; i++) {
	        if (items[i].checked == true) {
	            if (wantSend == "") 
	            	wantSend = items[i].value;
	            else 
	            	wantSend = wantSend + "," + items[i].value;
	        }
	    }
	}else{
		if(items.checked == true){
			  wantSend = items.value;		   	 
		}
	}
	if (wantSend == "") {
		alert("${addressUser_list_label5}");
		return false;
	}
	if(document.getElementById("Constants_webIM").name == "true"){
		webIM_openClientChatWindow("user"+wantSend.replace(/\,/g,"user"));
	}else{
		openwin('<c:url value="/modules/message/messages.do?method=popup&openwin=true&userId=" />'+wantSend,100,100,500,300,'yes');
	}
}
function addUser(){
   window.location.href='<c:url value="/modules/address/addressUser.do?method=addGroupUser&groupId=${param.groupId}" />'; 
}
function isOnsubmit(form) {
	var wantSend = "";
    var items = document.getElementsByName('itemlist');
    if(items.length>0) {
	    for (var i = 0; i < items.length; i++) {
	        if (items[i].checked == true) {
	            if (wantSend == "") 
	            	wantSend = items[i].value;
	            else 
	            	wantSend = wantSend + "," + items[i].value;
	        }
	    }
	}else{
		if(items.checked == true){
			  wantSend = items.value;		   	 
		}
	}
	if (wantSend == "") {
		alert("${addressUser_list_label17}!");
		return false;
	}else{
		var itemlists = wantSend.split(",");
		if(confirm("${addressUser_list_label18}?")){
			//form.action='<c:url value="/modules/address/addressUser.do?method=joinAddressUser&join=false&show=${param.show}&search_id=${param.search_id}&addressUser=${param.groupId}&showname=${param.showname}&action=move&itemlist=" />'+itemlists;
			form.action=form.action+'&itemlist='+itemlists;
			//alert(form.action);
			return true;
		}else{
			return false;
		}		
	}
}
function deleteuser(groupid){
    var wantSend = "";
    var items = document.getElementsByName('itemlist');
    if(items.length>0) {
	    for (var i = 0; i < items.length; i++) {
	        if (items[i].checked == true) {
	            if (wantSend == "") 
	            	wantSend = items[i].value;
	            else 
	            	wantSend = wantSend + "," + items[i].value;
	        }
	    }
	}else{
		if(items.checked == true){
			  wantSend = items.value;		   	 
		}
	}
	if (wantSend == "") {
		alert("${addressUser_list_label17}!");
		return false;
	}else{
		var itemlists = wantSend.split(",");
		if(confirm("${addressUser_list_label18}?")){
			//form.action='<c:url value="/modules/address/addressUser.do?method=joinAddressUser&join=false&show=${param.show}&search_id=${param.search_id}&addressUser=${param.groupId}&showname=${param.showname}&action=move&itemlist=" />'+itemlists;
			 var form = document.forms.ec;
		     form.action='<c:url value="/modules/address/addressUser.do?method=joinAddressUser&join=false&show=${param.show}&search_id=${param.search_id}&addressUser='+groupid+'&showname=${param.showname}&action=move&itemlist=" />'+itemlists;
			 form.submit();
			return true;
		}else{
			return false;
		}		
	}

}
//Delete_Cookie('friendTree');
//alert(Get_Cookie('friendTree'));
//2011-10-04,zxq,DMP:PT053734,RMP:R110801-0111,打开或关闭好友树
//2011-10-17,zxq,将展开/收起的图标反向调整，虽不合理但也只能按照需求要求做了。
function friendTree(){
    if(Get_Cookie('friendTree')==null){
    	Set_Cookie('friendTree','show');
    }
    var cook = Get_Cookie('friendTree');
	if(cook=='show'){
		
		$('friendTree').src = "<c:url value="/themes/${sessionScope.loginUser.theme}/skin/${sessionScope.loginUser.themePath}/images/advanced_search.gif"/>";
		$('friendTree').title = "${addressUser_addSystemUser_label7}";
		
		$('friendTreeMain').style.display = "none";
		$('friendTreeSetting').style.display = "none";
		
		$('friendTreeRow').style.height = "28px";
		$('topAddressRow').style.height = "98%";
		Set_Cookie('friendTree','hidden');
	}else{
		$('friendTree').src = "<c:url value="/themes/${sessionScope.loginUser.theme}/skin/${sessionScope.loginUser.themePath}/images/basic_search.gif"/>";
		$('friendTree').title = "${addressUser_addSystemUser_label6}";

		$('friendTreeMain').style.display = "";
		$('friendTreeSetting').style.display = "";
		
		$('friendTreeRow').style.height = "50%";
		$('topAddressRow').style.height = "50%";
		Set_Cookie('friendTree','show');
	}
	
}
</script>

<TABLE height="100%">
<tr><td>
<TABLE width="100%" height="29" border=0 cellPadding=0 cellSpacing=0>
  <TBODY>
	 <TR>
		 <TD >
	        <INPUT  class=${(param.type==null||param.type=='system')?'buttonOver':'button'}
        	 type=button style="width:64px;height:25;"
	         value="${addressUser_list_label1}" 
	         onclick="javascript:location.href='<c:url value="/modules/address/addressUser.do?method=list&show=addressuserGroup&type=system"/>'">
	       <INPUT  class=${(param.type=='0')?'buttonOver':'button'}
	      	 type=button  style="width:64px;height:25;"
	         value="${addressContact_list_label1}${addressContact_list_label3}" 
	         onclick="javascript:location.href='<c:url value="/modules/address/addressContact.do?method=list&type=0"/>'" > 
	       <INPUT class=${(param.type=='1')?'buttonOver':'button'}
             type=button style="width:64px;height:25;"
	         value="${addressContact_list_label2}${addressContact_list_label3}" 
	         name=cancel_button onclick="javascript:location.href='<c:url value="/modules/address/addressContact.do?method=list&type=1"/>'"> 
	      </TD>    
      </TR>
  </TBODY>
</TABLE>
</td></tr>

<tr id="topAddressRow" height="50%"><td>
<TABLE id="topAddress" class=leftColumnModuleHead cellSpacing=0 cellPadding=0  width="100%" height="100%" border=0 valign="top">
  <TBODY>
  <TR>
  <td valign="top">
	<iframe src='<c:url value="/modules/address/${(param.type==null||(param.type !='1'&&param.type !='0'))?'addressUser.do':'addressGroup.do'}?method=createLeftTree&search_id=${param.search_id == null?null:param.search_id}&deptCode=${param.deptCode}&scrollHight=${param.scrollHight}&openwin=true&type=${param.type == null?'system':param.type}" />' 
		width="200" frameborder="0" marginheight="0" marginwidth="0" allowTransparency="true"
		scrolling="auto" height="100%" class="contentBox" onload="resetScroll()" id='frame1' ></iframe>	
  </td>
  </TR>
  </TBODY>
</TABLE>

</td></tr>
<tr id="friendTreeRow" height="50%"><td valign="top">
<TABLE class=leftColumnModuleHead cellSpacing=0 cellPadding=0 
  width="100%" border=0 valign="top">
  <TBODY>
  <TR>
    <TH class="menu_title_left" width=48>&nbsp;</TH>
    <TH class="menu_title_middle">
    <table style="font-weight:bold;">
    	<tr height="22px">
	    	<td>${menu_address_label1}</td>
	    	<td>
			    <img onclick="friendTree();" id="friendTree" style="cursor:hand;" title="${addressUser_addSystemUser_label7}" align="absmiddle" border="0" src="<c:url value="/themes/${sessionScope.loginUser.theme}/skin/${sessionScope.loginUser.themePath}/images/basic_search.gif"/>"/>
	    	</td>
    	</tr>
    	<tr id="friendTreeSetting">
	    	<td>
		    	<a class=subMenuLink href="<c:url value="/modules/address/addressUser.do?method=myFriendGroup&type=${param.type}&search_id=1000000"/>">
			    	<font color="#CC0016">${addressUser_addSystemUser_label9}</font>
			    </a>
	    	</td>
    	</tr>
    </table>
    </TH>
    <th width="48" align="right" class="menu_title_right"></th></TR></TBODY></TABLE>
<TABLE id="friendTreeMain" class=subMenu cellSpacing=0 cellPadding=0 style="width:200px;table-layout:fixed;word-break: break-all; word-wrap: break-word;"  border=0>
	<TBODY>	
	<c:forEach items="${addressUserss}" var="addressUsers">
	  <TR>
	    <TD class=subMenuTDIcon style="border-bottom:1px solid #a1c6e7"
	    style="BACKGROUND-IMAGE: url(../../themes/${sessionScope.loginUser.theme}/images/createBg.gif); BACKGROUND-REPEAT: repeat-y" 
	    width=25><A class=subMenuLink 
	      onmouseover="document.getElementById('submenu_addressUsers${addressUsers.id}').style.background='#f2f4fb';" 
	      onmouseout="document.getElementById('submenu_addressUsers${addressUsers.id}').style.background='#ffffff';" 
	      href="javascript:showDetail('address_user_main_right','<c:url value="/modules/address/addressUser.do?method=showGroupUser&search_id=${addressUsers.id}&groupId=${addressUsers.id}&showname=${addressUsers.name}&type=friend"/>')"><IMG 
	      height=16 alt="${addressUsers.name}" 
	      src="../../themes/${sessionScope.loginUser.theme}/images/imgfolder.gif" 
	      width=16 align=absMiddle border=0 ></A></TD>
	    <TD class=subMenuTD id=submenu_addressUsers${addressUsers.id} style="border-bottom:1px solid #a1c6e7"
	    onmouseover="this.style.background='#f2f4fb';this.style.cursor='hand';" 
	    onmouseout="this.style.background='#ffffff';this.style.cursor='auto';" 
	    noWrap>&nbsp;<A class=subMenuLink  title="${addressUsers.name}"
	      href="javascript:showDetail('address_user_main_right','<c:url value="/modules/address/addressUser.do?method=showGroupUser&search_id=10000${addressUsers.id}&groupId=${addressUsers.id}&type=friend"/>')">
	     <c:if test="${fn:length(addressUsers.name)>12}"> ${fn:substring(addressUsers.name, 0,12)}...</c:if>
	     <c:if test="${fn:length(addressUsers.name)<=12}"> ${fn:substring(addressUsers.name, 0,fn:length(addressUsers.name))}</c:if>
	      </A></TD></TR>	
	</c:forEach>
	</TBODY>
</TABLE>
</td></tr>
</TABLE>
<script>
initfriendTree();
function resetScroll(obj){
	setTimeout(setScrollTop,1000)
}
function setScrollTop(){
	document.getElementById("frame1").contentWindow.document.body.scrollTop='${param.scrollHight}';
}
function initfriendTree(){
    if(Get_Cookie('friendTree')==null){
    	Set_Cookie('friendTree','show');
    }
    var cook = Get_Cookie('friendTree');
  
	if(cook=='hidden'){
		$('friendTree').src = "<c:url value="/themes/${sessionScope.loginUser.theme}/skin/${sessionScope.loginUser.themePath}/images/advanced_search.gif"/>";
		$('friendTree').title = "${addressUser_addSystemUser_label7}";
		
		$('friendTreeMain').style.display = "none";
		$('friendTreeSetting').style.display = "none";
		
		$('friendTreeRow').style.height = "28px";
		$('topAddressRow').style.height = "98%";
	}else{ 
		$('friendTree').src = "<c:url value="/themes/${sessionScope.loginUser.theme}/skin/${sessionScope.loginUser.themePath}/images/basic_search.gif"/>";
		$('friendTree').title = "${addressUser_addSystemUser_label6}";

		$('friendTreeMain').style.display = "";
		$('friendTreeSetting').style.display = "";
		
		$('friendTreeRow').style.height = "50%";
		$('topAddressRow').style.height = "50%";
	}	
}
</script>